package com.briup.cms.aop;

import com.briup.cms.bean.BaseLog;
import com.briup.cms.dao.BaseLogMapper;
import com.briup.cms.utils.UserInfo;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Aspect
@Component
public class LogAspect {
    @Autowired
    private BaseLogMapper mapper;
    @Pointcut("execution(* com.briup.cms.web.controller.*.*(..)) && @annotation(Logging)")
    public void logCutPoint() {
}
@Before("logCutPoint()")
        public void BeforeAdvice(){
        Map<String,Object> userInfo= UserInfo.getUserInfo();
        BaseLog baseLog=new BaseLog();
        baseLog.setLogUsername((String) userInfo.get("username"));
        baseLog.setLogRealname((String) userInfo.get("realname"));
        baseLog.setLogRequestMethod((String) userInfo.get("method"));
        baseLog.setLogRequestUri((String) userInfo.get("uri"));
        baseLog.setLogTime(new Date());
        mapper.insert(baseLog);
    }
}

